package com.zhongshengnetwork.rightbe.common.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
//import android.support.annotation.Nullable;

import androidx.annotation.Nullable;

import com.gyf.barlibrary.BarHide;
import com.gyf.barlibrary.ImmersionBar;
import com.zhongshengnetwork.rightbe.Adv.activity.SplashActivity;
import com.zhongshengnetwork.rightbe.MainActivity;
import com.zhongshengnetwork.rightbe.R;
import com.zhongshengnetwork.rightbe.common.AppThemeUtils;
import com.zhongshengnetwork.rightbe.common.AppUtils;

////import cn.jiguang.analytics.android.api.JAnalyticsInterface;
import me.imid.swipebacklayout.lib.SwipeBackLayout;
import me.imid.swipebacklayout.lib.app.SwipeBackActivity;

public class BaseTransparentActivity extends SwipeBackActivity {

    private SwipeBackLayout mSwipeBackLayout;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (AppUtils.getInstance().getAppStatus() == AppUtils.STATUS_FORCE_KILLED){
            //app被系统回收了，重新启动应用
            protectApp();
            return;
        }
        // 所有子类都将继承这些相同的属性,请在设置界面之后设置
        ImmersionBar.with(this)
                .statusBarColor(AppThemeUtils.getInstance().getThemeColorString())//R.color.transparent
                .navigationBarColor(AppThemeUtils.getInstance().getMainColorString()) //设置导航栏（虚拟键盘的颜色）
                .hideBar(BarHide.FLAG_SHOW_BAR)
                //.fitsSystemWindows(true)  //使用该属性必须指定状态栏的颜色，不然状态栏透明，很难看
                .init();
        // 可以调用该方法，设置是否允许滑动退出
        setSwipeBackEnable(false);
        mSwipeBackLayout = getSwipeBackLayout();
        // 设置滑动方向，可设置EDGE_LEFT, EDGE_RIGHT, EDGE_ALL, EDGE_BOTTOM
        mSwipeBackLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT);
        // 滑动退出的效果只能从边界滑动才有效果，如果要扩大touch的范围，可以调用这个方法
        mSwipeBackLayout.setEdgeSize(200);


    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        // 如果你的app可以横竖屏切换，并且适配4.4或者emui3手机请务必在onConfigurationChanged方法里添加这句话
        /*
        ImmersionBar.with(this)
                .statusBarColor(AppThemeUtils.getInstance().getThemeColorString())
                .navigationBarColor(AppThemeUtils.getInstance().getMainColorString()) //设置导航栏（虚拟键盘的颜色）
                .fitsSystemWindows(true)  //使用该属性必须指定状态栏的颜色，不然状态栏透明，很难看
                .init();
        */
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // 必须调用该方法，防止内存泄漏
        ImmersionBar.with(this).destroy();
    }

    @Override
    protected void onResume() {
        super.onResume();
        if(AppUtils.getInstance().isUserAgreeStatus() == false){
    return;
}
////JAnalyticsInterface.onPageStart(getApplicationContext(),this.getClass().getCanonicalName());
    }


    @Override
    protected void onPause() {
        super.onPause();
        if(AppUtils.getInstance().isUserAgreeStatus() == false){
    return;
}
////JAnalyticsInterface.onPageEnd(getApplicationContext(),this.getClass().getCanonicalName());
    }

    protected void protectApp() {
//        Intent intent = new Intent(this, MainActivity.class);
//        intent.putExtra(AppUtils.KEY_HOME_ACTION, AppUtils.ACTION_RESTART_APP);
//        startActivity(intent);

        Intent intent = new Intent(this, SplashActivity.class);
        startActivity(intent);
        System.exit(0);
        finish();

//        final Intent intent = getPackageManager().getLaunchIntentForPackage(getPackageName());
//        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//        startActivity(intent);

        //杀掉以前进程
        //android.os.Process.killProcess(android.os.Process.myPid());
    }

    /*
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_app_base);
        //适配全面屏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

            getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            //顶部状态栏
            getWindow().setStatusBarColor(Color.parseColor("#99CC00"));
            //底部导航栏
            getWindow().setNavigationBarColor(Color.WHITE);

        }
    }
    */

}
